<template>
	<div class="container">
		<div class="jx-return-container">
      <i class="iconfont icon-back" @click="back"></i><span class="cube-title">公告</span>
    </div>
    <el-form ref="form" :model="params_list" :rules="rules" label-width="130px" class="jx-form">
      <div class="jx-detail">
        <el-form-item label="用户类型：" prop="bc">
          <el-select class="tel-value" v-model="params_list.bc" placeholder="请选择">
            <el-option label="用户" value="用户"></el-option>
            <el-option label="商户" value="商户"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标题：" prop="announcementTitle">
          <el-input v-model="params_list.announcementTitle" placeholder="请输入标题"></el-input>
        </el-form-item>
        <el-form-item label="公告内容：" prop="announcementContent">
          <vue-editor :content="params_list.announcementContent" @getcontent="getcontent"></vue-editor>
        </el-form-item>
      </div> 
    </el-form>
    <div class="btn-container">
      <el-button class="jx-btn" type="warning">取消</el-button>
      <el-button class="jx-btn" type="primary" :loading="boo.saveing" @click="submitRow('form')">保存</el-button>
    </div>
	</div>
</template>

<script>
  import VueEditor from '@/components/common/VueEditor'
	export default {
    components: { VueEditor },
		data() {
			return {
        https: {
          add: this.$api.setting.bulletin.add,
          type: this.$api.setting,
        },
        boo: {
          saveing: false,
        },
        params_list: {
          announcementTitle: '',
          bc: '',
          announcementContent: '',
        },
        rules: {
          announcementTitle: [{ required: true, message: '请输入标题', trigger: 'blur' }],
          bc: [{ required: true, message: '请选择用户类型', trigger: 'change' }],
          announcementContent: [{ required: true, message: '请输入公告内容', trigger: 'blur' }],
        },
			}
		},
		mounted(){
      let _self = this
    },
		methods: {
      back(){
        history.go(-1)
      },
      getcontent(val){
        this.params_list.announcementContent = val
      },
      submitRow(formName){
        let _self = this
				this.$refs[formName].validate((vaild)=>{
					if(vaild){  
            let params = {
              announcementTitle: _self.params_list.announcementTitle,
              bc: _self.params_list.bc,
              announcementContent: _self.params_list.announcementContent,
            }
            _self.boo.saveing = true
            let success = (res)=>{
              res = res.data
              if(res.retCode == 1){
                history.go(-1)
              }else{
                _self.$message.error(res.retMsg)
              }
              _self.boo.saveing = false
            }
            _self.$axios.post(_self.https.add, params, success)
					}else{
						return false
          }
        })
      },
    }
	}

</script>
<style scoped lang="sass">
  .jx-form .el-form-item__label
    color: #333
</style>
